﻿using System;
using System.Web.UI;
using BLL;
using DAL;
using Ext.Net;

namespace ERP.Modules
{
    public partial class LogReportReceipt : UserControl
    {
        #region[Controller]
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                GetLogReportReceipt();
                btnDel.Disable(true);
                btnExport.Disable(true);
            }
        }
        protected void StoreLogReceipt_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            txtSearch.Text = string.Empty;
            txtDateBeginFillter.Text = string.Empty;
            txtDateEndFillter.Text = string.Empty;
            GetLogReportReceipt();
        }
        protected void btnDel_Click(object sender, DirectEventArgs e)
        {
            var sm = grLogReceipt.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (var row in sm.SelectedRows)
                {
                    try
                    {
                        var obj = new EtLogReportReceipt { Id_log = int.Parse(row.RecordID) };
                        BllLogReportReceipt.Delete(obj);
                    }
                    catch (Exception)
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                    }
                }
            GetLogReportReceipt();
        }
        protected void MenuItemExportExcel_Click(object sender, DirectEventArgs e)
        {
            
        }
        protected void btnFillter_Click(object sender, DirectEventArgs e)
        {
            GetLogReportReceipt();
        }
        protected void Search_Event(object sender, DirectEventArgs e)
        {
            var _clsGetLogReportReceipt = new BllLogReportReceipt();
            var _dtGetLogReportReceipt = _clsGetLogReportReceipt.GetLogReportReceipt(txtSearch.Text,
                string.Empty, string.Empty);
            if (_dtGetLogReportReceipt != null && _dtGetLogReportReceipt.Rows.Count > 0)
            {
                StoreLogReceipt.DataSource = _dtGetLogReportReceipt;
                StoreLogReceipt.DataBind();
            }
            else
            {
                grLogReceipt.GetStore().RemoveAll();
            }
        }
        #endregion

        #region[Method]
        private void GetLogReportReceipt()
        {
            var _clsGetLogReportReceipt = new BllLogReportReceipt();
            var _dtGetLogReportReceipt = _clsGetLogReportReceipt.GetLogReportReceipt(txtSearch.Text,
                txtDateBeginFillter.Text, txtDateEndFillter.Text);
            if (_dtGetLogReportReceipt != null && _dtGetLogReportReceipt.Rows.Count > 0)
            {
                StoreLogReceipt.DataSource = _dtGetLogReportReceipt;
                StoreLogReceipt.DataBind();
            }
            else
            {
                grLogReceipt.GetStore().RemoveAll();
            }
        }
        #endregion
    }
}